package data.bot;

import java.util.Calendar;

import data.wg.WGProvince;

public class LandingContainer extends AbstractBattleContainer
{
	public WGProvince wgprovince;
	public LandingContainer(WGProvince wgprovince)
	{
		this.wgprovince=wgprovince;
		idOfContent = wgprovince.name.hashCode();
	}
	
	
	public void calculateTimeAndFinalityOfCombat()
	{
		isFinal = wgprovince.landingFinalBattleTime!=null;
		if(isFinal)
		{
			time = wgprovince.landingFinalBattleTime;
		}
		else
		{
			time = wgprovince.primetime + 60 * 30+ getRounds(wgprovince.landingCompetitorsCount)* 60*30;
		}
	}
	
	private int getRounds(int members)
	{
		int log =(int) (Math.log(members)/Math.log(2));
		
		return log;
	}

	@Override
	public String getString(StringMode sm) {
		switch(sm)
		{
		case CombatList:
			return getCombatListString();
		case BattleReminderTaskString:
			return getBattleReminderTaskString();
		}

		return "Invalid StringMode";
	}
	
	public String getBattleReminderTaskString()
	{
		String minutes;
		Calendar atCalendar = Calendar.getInstance();
		atCalendar.setTimeInMillis(time*1000);

		
		
		int min = atCalendar.get(Calendar.MINUTE);
		if(min<10)
		{
			minutes = "0"+min;
		}
		else
		{
			minutes=min+"";
		}
		
		if(isFinal)
		{
			return atCalendar.get(Calendar.HOUR_OF_DAY)+":"+minutes+" (Landing "+wgprovince.FULLNAME+")";
		}
		return "battle reminders should not be existant for nonfinal battles!";
	}
	
	public String getCombatListString()
	{
		String minutes;
		Calendar atCalendar = Calendar.getInstance();
		atCalendar.setTimeInMillis(time*1000);

		
		
		int min = atCalendar.get(Calendar.MINUTE);
		if(min<10)
		{
			minutes = "0"+min;
		}
		else
		{
			minutes=min+"";
		}
		
		if(isFinal)
		{
			return atCalendar.get(Calendar.HOUR_OF_DAY)+":"+minutes+" (Landing "+wgprovince.FULLNAME+")";
		}
		return atCalendar.get(Calendar.HOUR_OF_DAY)+":"+minutes+"+ (Landing "+wgprovince.FULLNAME+")";
	}


}
